markdown-text-editor 1.9.2 → 1.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/markdown-text-editor.es.js +13 -0
- package/dist/markdown-text-editor.es.js.map +1 -1
- package/dist/markdown-text-editor.min.js +6 -6
- package/dist/markdown-text-editor.min.js.map +1 -1
- package/dist/markdown-text-editor.umd.js +6 -6
- package/dist/markdown-text-editor.umd.js.map +1 -1
- package/package.json +1 -1
- package/types/index.d.ts +10 -0
|
@@ -2433,6 +2433,14 @@ var On = Dn(), Z = class {
|
|
|
2433
2433
|
constructor(e, t) {
|
|
2434
2434
|
this.editor = e, this.defaultText = `${t} text`, this.button = this.createButton(), this.title = t;
|
|
2435
2435
|
}
|
|
2436
|
+
trimSelection() {
|
|
2437
|
+
let e = this.editor.usertextarea, { selectionStart: t, selectionEnd: n, value: r } = e;
|
|
2438
|
+
if (t === n) return;
|
|
2439
|
+
let i = t, a = n;
|
|
2440
|
+
for (; i < a && /\s/.test(r[i]);) i++;
|
|
2441
|
+
for (; a > i && /\s/.test(r[a - 1]);) a--;
|
|
2442
|
+
i !== a && (i !== t || a !== n) && e.setSelectionRange(i, a);
|
|
2443
|
+
}
|
|
2436
2444
|
createButton(e) {
|
|
2437
2445
|
let t = document.createElement("button"), n = this.title ? `${this.title.replace(/ /g, "-")}-btn`.toLowerCase() : "";
|
|
2438
2446
|
t.innerHTML = e;
|
|
@@ -2448,6 +2456,7 @@ var On = Dn(), Z = class {
|
|
|
2448
2456
|
super(e, "Bold"), this.button = this.createButton("\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"/><path d=\"M7 5h6a3.5 3.5 0 0 1 0 7h-6l0 -7\" /><path d=\"M13 12h1a3.5 3.5 0 0 1 0 7h-7v-7\" /></svg>\n ");
|
|
2449
2457
|
}
|
|
2450
2458
|
applySyntax() {
|
|
2459
|
+
this.trimSelection();
|
|
2451
2460
|
let e = this.editor.usertextarea, { selectionStart: t, selectionEnd: n } = e, r = e.value, i = r.substring(t, n), a = "", o = 0;
|
|
2452
2461
|
if (i.startsWith("***") && i.endsWith("***")) a = "*" + i.slice(3, -3) + "*";
|
|
2453
2462
|
else if (i.startsWith("**") && i.endsWith("**")) a = i.slice(2, -2);
|
|
@@ -2465,6 +2474,7 @@ var On = Dn(), Z = class {
|
|
|
2465
2474
|
super(e, "Italic"), this.button = this.createButton("\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"/><path d=\"M11 5l6 0\" /><path d=\"M7 19l6 0\" /><path d=\"M14 5l-4 14\" /></svg>\n ");
|
|
2466
2475
|
}
|
|
2467
2476
|
applySyntax() {
|
|
2477
|
+
this.trimSelection();
|
|
2468
2478
|
let e = this.editor.usertextarea, { selectionStart: t, selectionEnd: n } = e, r = e.value, i = r.substring(t, n), a = "", o = 0;
|
|
2469
2479
|
if (i.startsWith("***") && i.endsWith("***")) a = "**" + i.slice(3, -3) + "**";
|
|
2470
2480
|
else if (i.startsWith("*") && i.endsWith("*") && !i.startsWith("**")) a = i.slice(1, -1);
|
|
@@ -2482,6 +2492,7 @@ var On = Dn(), Z = class {
|
|
|
2482
2492
|
super(e, "Strikethrough"), this.button = this.createButton("\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"/><path d=\"M5 12l14 0\" /><path d=\"M16 6.5a4 2 0 0 0 -4 -1.5h-1a3.5 3.5 0 0 0 0 7h2a3.5 3.5 0 0 1 0 7h-1.5a4 2 0 0 1 -4 -1.5\" /></svg>\n ");
|
|
2483
2493
|
}
|
|
2484
2494
|
applySyntax() {
|
|
2495
|
+
this.trimSelection();
|
|
2485
2496
|
let e = this.editor.usertextarea, { selectionStart: t, selectionEnd: n } = e, r = e.value, i = r.substring(t, n), a = "", o = 0;
|
|
2486
2497
|
if (i.startsWith("~~") && i.endsWith("~~")) a = i.slice(2, -2);
|
|
2487
2498
|
else if (r.substring(t - 2, t) === "~~" && r.substring(n, n + 2) === "~~") {
|
|
@@ -2601,6 +2612,7 @@ var $ = class extends Z {
|
|
|
2601
2612
|
super(e, "Link"), this.button = this.createButton("\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"/><path d=\"M9 15l6 -6\" /><path d=\"M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .464\" /><path d=\"M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463\" /></svg>\n ");
|
|
2602
2613
|
}
|
|
2603
2614
|
applySyntax(e) {
|
|
2615
|
+
this.trimSelection();
|
|
2604
2616
|
let t = this.editor, n = t.usertextarea, { selectionStart: r, selectionEnd: i } = n, a = n.value, o = a.substring(0, r), s = a.substring(i);
|
|
2605
2617
|
if (o.endsWith("[") && /^\]\([^)]+\)/.test(s)) {
|
|
2606
2618
|
let e = s.match(/^\]\(([^)]+)\)/);
|
|
@@ -2790,6 +2802,7 @@ var zn = class extends Z {
|
|
|
2790
2802
|
super(e, "Code"), this.button = this.createButton("\n <svg xmlns=\"http://www.w3.org/2000/svg\" width=\"20\" height=\"20\" viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\" stroke-linecap=\"round\" stroke-linejoin=\"round\"><path stroke=\"none\" d=\"M0 0h24v24H0z\" fill=\"none\"/><path d=\"M7 8l-4 4l4 4\" /><path d=\"M17 8l4 4l-4 4\" /><path d=\"M14 4l-4 16\" /></svg>\n ");
|
|
2791
2803
|
}
|
|
2792
2804
|
applySyntax() {
|
|
2805
|
+
this.trimSelection();
|
|
2793
2806
|
let e = this.editor.usertextarea, { selectionStart: t, selectionEnd: n } = e, r = e.value, i = r.substring(t, n);
|
|
2794
2807
|
if (i.startsWith("`") && i.endsWith("`")) {
|
|
2795
2808
|
this.editor.insertText(i.slice(1, -1), 0, 0);
|